package com.tanhua.admin.controller;

import com.tanhua.admin.service.ManageService;
import com.tanhua.model.mongo.Video;
import com.tanhua.model.pojo.UserInfo;
import com.tanhua.model.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/manage")
public class ManageController {

    @Resource
    private ManageService manageService;

    //查询用户列表
    @GetMapping("/users")
    public ResponseEntity users(@RequestParam(defaultValue = "1") Integer page,
                                @RequestParam(defaultValue = "10") Integer pagesize){
        PageResult pr = manageService.users(page,pagesize);
        return ResponseEntity.ok(pr);
    }

    //用户基本资料
    @GetMapping("/users/{userID}")
    public ResponseEntity userInfo(@PathVariable("userID") Long userId){
        UserInfo userInfo = manageService.userInfo(userId);
        return ResponseEntity.ok(userInfo);
    }

    //查看视频列表
    @GetMapping("/videos")
    public ResponseEntity videos(@RequestParam(defaultValue = "1") Integer page,
                                 @RequestParam(defaultValue = "10") Integer pagesize,
                                 Long uid){
        PageResult pr = manageService.videos(page,pagesize,uid);
        return ResponseEntity.ok(pr);
    }

    //查看动态列表
    @GetMapping("/messages")
    public ResponseEntity messages(@RequestParam(defaultValue = "1") Integer page,
                                   @RequestParam(defaultValue = "10") Integer pagesize,
                                   Long uid,
                                   Integer state){
        PageResult pr = manageService.messages(page,pagesize,uid,state);
        return ResponseEntity.ok(pr);
    }

    //用户冻结
    @PostMapping("/users/freeze")
    public ResponseEntity freeze(@RequestBody Map map){
        String message = manageService.freeze(map);
        Map retMap = new HashMap();
        retMap.put("message",message);
        return ResponseEntity.ok(retMap);
    }

    //用户解冻
    @PostMapping("/users/unfreeze")
    public ResponseEntity unfreeze(@RequestBody Map map){
        Map retMap = manageService.unfreeze(map);
        return ResponseEntity.ok(retMap);
    }
}
